﻿using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine;
using UnityEngine.Scripting;
using GMME.Util;

namespace GMME.Model.Rtm.Result
{
    [DataContract]
    public class GetRtmSubscribedChannelInfoResult : ErrorResult
    {
        /**
         * 开发者已订阅频道Id集合
         */
        [DataMember(Name = "channelIds")]
        [Preserve]
        public List<string> ChannelIds { get; set; }

#if UNITY_ANDROID
        internal static List<string> JavaListToStringList(AndroidJavaObject javaList)
        {
            if (javaList == null)
            {
                return new List<string>();
            }

            int count = javaList.Call<int>("size");
            List<string> stringList = new List<string>(count);
            for (int i = 0; i < count; i++)
            {
                stringList.Add(javaList.Call<string>("get", i));
            }

            return stringList;
        }

        internal static GetRtmSubscribedChannelInfoResult ConvertGetRtmSubscribedChannelInfoResult(
            AndroidJavaObject javaObject)
        {
            var result = new GetRtmSubscribedChannelInfoResult();
            if (javaObject != null)
            {
                result.ChannelIds = JavaListToStringList(
                    javaObject.Call<AndroidJavaObject>("getChannelIds"));
                result.Code = javaObject.Call<int>("getCode");
                result.Msg = javaObject.Call<string>("getMsg");
                return result;
            }

            return null;
        }
#endif
    }
}